package com.example.baseexercises.Redis;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: 辛之所想
 * @create: 2025-11-15 20:42
 * @description:
 **/

@RestController
@RequestMapping("/redisList")
@Tag(name = "RedisList",description = "RedisList操作")
public class RedisList {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;


    @GetMapping("/redisListTest")
    @Operation(summary = "RedisList测试")
    public List<String> redisListTest() {
        set("redisList", List.of("redisList1", "redisList2"));
        return get("redisList");
    }
    public void set(String key, List<String> value) {
        stringRedisTemplate.opsForList().rightPushAll(key, value);
    }

    public List<String> get(String key) {
        return stringRedisTemplate.opsForList().range(key, 0, -1);
    }
}
